# Compiler and linker settings
CXX = g++
CXXFLAGS = -ggdb -O0 -std=c++98 -g -Wall -I../game/include 

# Project source and object files
SOURCES := SocketClient.cpp Socket.cpp
OBJECTS=$(SOURCES:.cpp=.o)

.PHONY: all
all: $(OBJECTS)

# if not 'make clean' then include dependency makefiles
ifeq (,$(findstring clean,$(MAKECMDGOALS)))

# include all dependency files
-include $(SOURCES:.cpp=.d)

# generate a .d (file with dependencies for a .o file) from the .cpp file
%.d: %.cpp
	@echo Generating dependency file for $<
	@set -e; rm -f $@; \
	$(CXX) $(CXXFLAGS) -MM -MF $@.temp $<; \
	sed 's,\($*\)\.o[: ]*,\1.o $@ : ,g' < $@.temp > $@; \
	rm -f $@.temp
endif

# Rule for compiling a .cpp file to a .o file
.cpp.o:
	@echo Compiling $<
	@$(CXX) $(CXXFLAGS) $< -c -o $@

# Remove all object and dependency files and the executable
.PHONY: clean
clean:
	@-rm -f $(SOURCES:.cpp=.d) $(OBJECTS)
